#!/usr/bin/env python
# -*- coding: UTF-8 -*-
"""
@Project    :icac2 
@File       :paginate.py
@Author     :wangfan13
@Date       :2021/5/24 11:50 
"""
from collections import OrderedDict

from rest_framework import views, fields, pagination
from rest_framework.response import Response


class PageSet(pagination.PageNumberPagination):
    # 页面大小
    page_size = 10
    page_size_query_param = "page_size"
    max_page_size = 10
    page_query_param = "page_num"

    def get_paginated_response(self, data):
        """
        设置返回内容格式
        :param data:
        :return:
        """
        return Response(OrderedDict([
            ('count', self.page.paginator.count),
            ('next', self.get_next_link()),
            ('previous', self.get_previous_link()),
            ('results', data),
            ('page_total', self.page.paginator.count),
            ('page_total', self.page.paginator.count),
            ('page_size', self.page.paginator.per_page),
            ('page_num', self.page.start_index() // self.page.paginator.per_page + 1),
        ]))
